#include <myhead.h>
#include "mypkg.h"

void test(){
	char buf[4096];
	int bufLen=pkg_pack_buf(buf,MSG_TYPE_SYSTEM,5,"aa","bb","cc","dd","e");
	for(int i=0;i<bufLen;i++){
		printf("%02X ", buf[i]);
		if((i+1)%16==0)
			printf("\n");
	}
	printf("\n");
	//
	char errmsg[1024]={0};
	printf("check=[%d]\n" , pkg_buf_check(buf, 4096, errmsg));
	//追加
	printf("#############追加测试#################\n");
	char byteArr[16]={1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8};
	bufLen=pkg_appendByteArr(buf, byteArr, 16);
	printf("check=[%d]\n" , pkg_buf_check(buf, 4096, errmsg));
	for(int i=0;i<bufLen;i++){
		printf("%02X ", buf[i]);
		if((i+1)%16==0)
			printf("\n");
	}
	printf("\n");
	printf("##############################\n");

	// 拆包测试
	pkg_t* retPkg=pkg_create();
	int ret=pkg_unpack(buf, retPkg);
	printf("**********拆包测试*****************\n");
	printf("param_num=[%d],ret=[%d]\n", retPkg->param_num, ret);
	for(int i=0;i< retPkg->param_num ;i++){
		char* msg=pkg_get(retPkg, i);
		printf("第[%d]个参数:[%s]\n", i, msg);
	}

	printf("-----------getbuf测试-------------\n");
	printf("第[5]个参数:\n");
	bufLen=0;
	char* buf2 = pkg_getbuf(retPkg, 5, &bufLen);
	for(int i=0;i<bufLen;i++){
		printf("%02X ", buf2[i]);
		if((i+1)%16==0)
			printf("\n");
	}
	printf("\n");
	printf("------------------------\n");

	pkg_free(retPkg);
}

int main(int argc, const char *argv[])
{
	test();
	//test();
	return 0;
}

